﻿@{
    ViewBag.Title = "CancelIndex";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<div class="topPanel" style="margin-bottom: 1%;">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control form-control-focus" placeholder="请输入卡号/住院号" style="width: 200px;">
                    </div>
                </td>
                <td style="padding-left:12px;">
                    <div class="btn-group" id="btnKeywordTypeGourp" style="margin-top:0;">
                        <button type="button" data-keywordtype="kh" class="btn active btn-restore">&nbsp;卡&nbsp;&nbsp;号&nbsp;</button>
                        <button type="button" data-keywordtype="zyh" class="btn btn-default">住院号</button>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>

<div class="rows" style="margin-bottom: 1%;" id="divPatHospitalizationBillBasicInfo">
    <div class="panel panel-default" style="margin-bottom:0;">
        <div class="panel-heading navb-bg">
            住院病人信息
        </div>
        <table class="form" style="width:96%;">
            <tr>
                <td class="formTitle">卡号：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" id="kh" value="" />
                </td>
                <td class="formTitle">住院号：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" id="zyh" value="" />
                </td>
                <td class="formTitle">病历号：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" id="blh" value="" />
                </td>
            </tr>
            <tr>
                <td class="formTitle">姓名：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" id="xm" value="" />
                </td>
                <td class="formTitle">性别：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" id="xb" value="" />
                </td>
                <td class="formTitle">年龄：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" id="nlshow" value="" />
                </td>
                <td class="formTitle">患者类型：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" id="brxzmc" value="" />
                </td>
            </tr>
            <tr>
                <td class="formTitle">住院科别：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" id="ksmc" value="" />
                </td>
                <td class="formTitle">床位：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" id="" value="" />
                </td>
                @*<td class="formTitle">预交金：</td>
                    <td class="formValue">
                        <input class="form-control" disabled readonly="readonly" type="text" value="" id="" />
                    </td>*@
                <td class="formTitle">总费用：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" value="" id="txtZJE" />
                </td>
            </tr>
            <tr>
                <td class="formTitle">入院日期：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" value="" id="ryrq" />
                </td>
                <td class="formTitle">出院日期：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" value="" id="cyrq" />
                </td>
                <td class="formTitle">住院天数：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" value="" id="zyts" />
                </td>
            </tr>
        </table>
    </div>
</div>


<div class="rows" style="margin-bottom: 1%;" id="divPatHospitalizationBillFeeInfo">
    <div class="panel panel-default" style="margin-bottom:0;">
        <div class="panel-heading navb-bg">
            结算信息
        </div>
        <table class="form" style="width:96%;">
            <tr>
                <td class="formTitle">结算类型：</td>
                <td class="formValue">
                    <input type="hidden" id="hfJSNM" />
                    <input class="form-control" disabled readonly="readonly" type="text" id="txtBillType" value="" />
                </td>
                <td class="formTitle"></td>
                <td class="formValue"></td>
                <td class="formTitle"></td>
                <td class="formValue"></td>
            </tr>
            <tr>
                <td class="formTitle">结算金额：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" value="" id="txtJSJE" />
                </td>
                <td class="formTitle">本次金额：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" value="" id="txtBCJE" />
                </td>
                <td class="formTitle">已结金额：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" value="" id="txtYJJE" />
                </td>
                <td class="formTitle"></td>
                <td class="formValue"></td>
            </tr>
            <tr>
                <td class="formTitle">记账支付：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" value="" id="txtJZZF" />
                </td>
                <td class="formTitle">个人支付：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" value="" id="txtGRZF" />
                </td>
                <td class="formTitle">账户余款：</td>
                <td class="formValue">
                    <input class="form-control" disabled readonly="readonly" type="text" value="" id="txtZHYK" />
                </td>
            </tr>
            <tr>
                <td class="formTitle">取消原因：</td>
                <td class="formValue" colspan="5">
                    <input class="form-control" type="text" value="" id="txtCancelReason" />
                </td>
            </tr>
        </table>
    </div>
</div>

<div class="toolbar" style="float:right;width:80%;margin:10px;text-align:right;">
    <a class="btn btn-primary btn-md" onclick="newtouch_globalevent_f4()">
        <i class="fa fa-close"> F4:清除</i>
    </a>
    <a class="btn btn-primary btn-md" onclick="newtouch_globalevent_f8()">
        <i class="fa fa-save"></i>F8:保存
    </a>
</div>

<script type="text/javascript">
    $('#btnKeywordTypeGourp').on('click', '.btn', function () {
        if (!$(this).hasClass('active')) {
            $(this).siblings('.btn').removeClass('btn-restore').removeClass('active').addClass('btn-default');
            $(this).removeClass('btn-default').addClass('btn-restore active');
        }
    });

    var txt_keyword = document.getElementById('txt_keyword');
    txt_keyword.addEventListener('keydown', function (event) {
        event = event || window.event;
        if (isLoadingIIII) {
            stopDefault(event); //数据加载过程中，阻止默认行为
            return false;
        }
        if (event.keyCode == 13) {
            ajaxLoadDataResult();
        }
    });

    //ajaxLoadResult
    var isLoadingIIII = false;  //是否正在从后台加载数据
    function ajaxLoadDataResult() {
        if (!isLoadingIIII) {
            isLoadingIIII = true;
            var keyword = $.trim($("#txt_keyword").val());
            if (keyword == '') {
                isLoadingIIII = false;
                return false;
            }
            $.loading(true, "正在请求数据...");
            var zyh = null;
            var kh = null;
            if ($('#btnKeywordTypeGourp .btn.active').attr('data-keywordtype') == 'kh') {
                kh = keyword;
            }
            else {
                zyh = keyword;
            }
            $.najax({
                type: "POST",
                url: "/HospitalizationManage/Settlement/CancelGetStatusDetail",
                data: { zyh: zyh, kh: kh },
                dataType: "json",
                success: function (ajaxresp) {
                    //住院病人基本信息
                    $('#divPatHospitalizationBillBasicInfo').formSerialize(ajaxresp.data.SettPatInfo);
                    $("#xb").val($.getGender(ajaxresp.data.SettPatInfo.xb));
                    $("#ryrq").val((ajaxresp.data.SettPatInfo.ryrq && ajaxresp.data.SettPatInfo.ryrq.length >= 10 ? ajaxresp.data.SettPatInfo.ryrq.substring(0, 10) : ""));
                    $("#cyrq").val((ajaxresp.data.SettPatInfo.cyrq && ajaxresp.data.SettPatInfo.cyrq.length >= 10 ? ajaxresp.data.SettPatInfo.cyrq.substring(0, 10) : ""));
                    $("#zyts").val((ajaxresp.data.SettPatInfo.zyts && ajaxresp.data.SettPatInfo.zyts > 0 ? ajaxresp.data.SettPatInfo.zyts.toFixed(1) : ""));
                    $("#nlshow").html(getAgeFromBirthTime({ begin: ajaxresp.data.SettPatInfo.csny }).text);

                    $("#hfJSNM").val(ajaxresp.data.LastUnCancelledSett.jsnm);
                    $("#txtZJE, #txtJSJE, #txtBCJE, #txtYJJE").val(ajaxresp.data.LastUnCancelledSett.zje.toFixed(2));
                    $("#txtGRZF").val(ajaxresp.data.LastUnCancelledSett.xjzf.toFixed(2));
                    $("#txtJZZF").val((ajaxresp.data.LastUnCancelledSett.zje - ajaxresp.data.LastUnCancelledSett.xjzf).toFixed(2));

                    $("#txtZHYK").val('0.00');

                    $('#txtBillType').val('出院结算');
                },
                errorCallback: function (data) {
                    funcDoPageClear();
                },
                complete: function () {
                    isLoadingIIII = false;
                    $.loading(false);
                }
            });
        }
    }

    window.newtouch_globalconfig.f4opions = {
        container: "#divPatHospitalizationBillBasicInfo, #divPatHospitalizationBillFeeInfo"
    };

    //清除操作
    var funcDoPageClear = function () {
        newtouch_globalevent_f4();
    };

    //取消结算
    function newtouch_event_f8() {
        var zyh = $.trim($('#zyh').val());
        var jsnm = $.trim($('#hfJSNM').val());
        if (!zyh || !jsnm) {
            return;
        }
        var cancelReason = $.trim($('#txtCancelReason').val());
        if (!cancelReason) {
            $.modalAlert("请填写取消原因", 'warning');
            //$('#txtCancelReason').trigger('focus');
            return;
        }
        postData = {};
        postData['zyh'] = zyh;
        //期望的结算内码 防止过程中变更
        postData['expectedjsnm'] = jsnm;
        postData['cancelReason'] = cancelReason;
        $.submitForm({
            url: "/HospitalizationManage/Settlement/SubmitCancel",
            param: postData,
            success: function (data) {
                location.href = location.href;
            }
        });

    }

</script>
